﻿(function () {
    "use strict";

    var nav = WinJS.Navigation;

    WinJS.UI.Pages.define("/pages/searchresults/searchresults.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        init: function (element, options) {

        },

        ready: function (element, options) {
            var backButton = document.getElementById("cmdBack").winControl;
            var homeButton = document.getElementById("cmdHome").winControl;
            var listView = document.getElementById("jobOffers").winControl;
            var showInfo = document.getElementById("cmdLoadInfo");

            backButton.addEventListener("click", function () {
                nav.back(1);
            });

            homeButton.addEventListener("click", function () {
                nav.navigate("/pages/home/home.html");
            });

            showInfo.addEventListener("click", function () {

                var text = "";

                listView.selection.getItems().then(function (items) {
                    if (items.length != 0) {

                        for (var i = 0; i < items.length; i++) {
                            text += "<h2>\nИме: " + items[i].data.title + "\n" + "</h2>";
                            text += "<h3>\nОписание: " + items[i].data.content + "\n" + "<h3>";
                            text += "<h3>\nАдрес: <a href=" + items[i].data.link + "\n" + ">" + items[i].data.link + "</a>\n\n<h3>";
                            text += "<br/>"
                        }
                    }

                    Data.saveText(text);
                });

                nav.navigate("/pages/loaded/loadedInfo.html");
            });
        }
    });
})();
